<?php
class log extends parent_class
{
	public $id=0;
	public $text="";
	public $ip="";
	public $type=0;
	public $user_id=0;
	public $date="";
	
	public function __construct($id=0)
	{
		if ($id!=0)
		{
			return $this->get($id);
		}
	}
	
	public function get($id=0)
	{
		if ($id==0)
		{
			if ($this->id!=0)
			{
				$id=$this->id;
			}
			else
			{
				return false;
			}
		}
		$id=intval($id);
		$query="SELECT * FROM logs WHERE `id`=".$id." LIMIT 1";
		if ($result=db::$db->query($query))
		{
			if ($result->num_rows==1)
			{
				$row=$result->fetch_object();
				 
				$this->id=$row->id;
				$this->text=$row->text;
				$this->date=$row->date;
				$this->ip=$row->ip;
				$this->type=$row->type;
				$this->userid=$row->userid;
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public function remove($id=0)
	{
		if ($id==0)
		{
			if ($this->id>0)
			{
				$id=$this->id;
			}
			else
			{
				return false;
			}
		}
		$id=intval($id);
		$query="DELETE FROM `logs` WHERE `id`=".$id." LIMIT 1";
		if (db::$db->query($query))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function add($type=0,$text="",$id=0,$ip="",$date="")
	{
		if (trim($date)=="")
		{
			$date=date("Y-m-d H:i:s");
		}
		if (trim($ip)=="")
		{
			$ip=$_SERVER["REMOTE_ADDR"];
		}
		$query=new query(db::$db);
		$query->addparam($type,"i");
		$query->addparam($text,"s");
		$query->addparam($ip,"s");
		$query->addparam($date,"s");
		$query->addparam($id,"i");
		$query->query("INSERT INTO `logs` VALUES (NULL, ?, ?, ?, ?, ?)");
	}
	
	public function returnit($str="")
	{
		$parse=new parser;
		$parse->additem("%id%",$this->id);
		$parse->additem("%type%",$this->type);
		$parse->additem("%date%",$this->date);
		$parse->additem("%ip%",$this->ip);
		$parse->additem("%userid%",$this->userid);
		$parse->additem("%text%",$this->text);
		return $parse->parse($str);
	}
}
?>